package com.hanhanxiaochong.zhongxiangchuanmei.view.main.act;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.gyf.barlibrary.ImmersionBar;
import com.hanhanxiaochong.zhongxiangchuanmei.R;
import com.hanhanxiaochong.zhongxiangchuanmei.bean.WalletMoneyBean;
import com.hanhanxiaochong.zhongxiangchuanmei.presenter.my.MyWalletPresenter;
import com.hanhanxiaochong.zhongxiangchuanmei.util.SharedPreferencesUtil;
import com.hanhanxiaochong.zhongxiangchuanmei.util.StringUtils;
import com.hanhanxiaochong.zhongxiangchuanmei.view.base.BaseActivity;
import com.hanhanxiaochong.zhongxiangchuanmei.view.iview.IMyWalletView;
import com.hanhanxiaochong.zhongxiangchuanmei.view.my.act.BankCardActivity;
import com.hanhanxiaochong.zhongxiangchuanmei.view.my.act.MyWalletLSMXActivity;
import com.hanhanxiaochong.zhongxiangchuanmei.view.my.act.RechargeActivity;
import com.hanhanxiaochong.zhongxiangchuanmei.view.my.act.StorRewardActivity;
import com.hanhanxiaochong.zhongxiangchuanmei.view.my.act.UserRewardActivity;
import com.hanhanxiaochong.zhongxiangchuanmei.view.my.act.WithdrawActivity;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Author : 贾桐
 * E-mail : 653773284@qq.com
 * Time   : 2018/5/10.
 * Desc   :
 */

public class MyWalletActivity extends BaseActivity<MyWalletPresenter> implements IMyWalletView {
    @BindView(R.id.img_left)
    ImageView imgLeft;
    @BindView(R.id.txt_title)
    TextView txtTitle;
    @BindView(R.id.txt_right)
    TextView txtRight;
    @BindView(R.id.ll_rightview)
    RelativeLayout llRightview;
    @BindView(R.id.rl_topview)
    RelativeLayout rlTopview;
    @BindView(R.id.txt_wallet_money)
    TextView txtWalletMoney;
    @BindView(R.id.txt_user_reward_money)
    TextView txtUserRewardMoney;
    @BindView(R.id.txt_stor_reward_money)
    TextView txtStorRewardMoney;

    private String token;
    private String userMoney, storMoney;

    @Override
    protected void initView() {
        setContentView(R.layout.activity_my_wallet);
        token = SharedPreferencesUtil.getsInstances(this).getLoginInfo().getToken();
    }

    @Override
    protected void initPresenter() {
        mPresenter = new MyWalletPresenter(this);
    }

    @Override
    protected void init() {
        ImmersionBar.with(MyWalletActivity.this).fitsSystemWindows(true).statusBarColor(R.color
                .red4).statusBarDarkFont(false).init(); //解决状态栏和布局重叠问题;
        rlTopview.setBackgroundColor(getResources().getColor(R.color.red4));
        imgLeft.setImageResource(R.mipmap.icon_close_white);
        txtTitle.setText("钱包");
        txtRight.setText("流水明细");
        txtTitle.setTextColor(getResources().getColor(R.color.white));
        txtRight.setTextColor(getResources().getColor(R.color.white));

        mPresenter.getWalletMoney(token);
    }

    @OnClick({R.id.ll_leftview, R.id.ll_rightview, R.id.txt_recharge, R.id.txt_bank_card, R.id.txt_withdraw, R.id.rl_user_reward, R.id.rl_stor_reward})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_leftview:
                finish();
                break;
            case R.id.ll_rightview:
                Intent intent = new Intent(this, MyWalletLSMXActivity.class);
                startActivity(intent);
                break;
            case R.id.txt_recharge:
                Intent intent1 = new Intent(this, RechargeActivity.class);
                startActivity(intent1);
                break;
            case R.id.txt_bank_card:
                Intent intent4 = new Intent(this, BankCardActivity.class);
                startActivity(intent4);
                break;
            case R.id.txt_withdraw:
                Intent intent5 = new Intent(this, WithdrawActivity.class);
                startActivity(intent5);
                break;
            case R.id.rl_user_reward:
                Intent intent2 = new Intent(this, UserRewardActivity.class);
                intent2.putExtra("money", userMoney);
                startActivity(intent2);
                break;
            case R.id.rl_stor_reward:
                Intent intent3 = new Intent(this, StorRewardActivity.class);
                intent3.putExtra("money", storMoney);
                startActivity(intent3);
                break;
        }
    }

    @Override
    public void getWalletMoney(WalletMoneyBean walletMoneyBean) {
        if (StringUtils.isEmpty(walletMoneyBean.getU_balance())){
            txtWalletMoney.setText("￥" + walletMoneyBean.getU_balance());
        }else {
            txtWalletMoney.setText("￥0");
        }
        if (StringUtils.isEmpty(walletMoneyBean.getStor_reward().getTixian_1())){
            storMoney = walletMoneyBean.getStor_reward().getTixian_1();
            txtStorRewardMoney.setText("￥" + walletMoneyBean.getStor_reward().getTixian_1());
        }else {
            txtStorRewardMoney.setText("￥0");
            storMoney = "0";
        }
        if (StringUtils.isEmpty(walletMoneyBean.getUser_reward().getTixian_1())){
            userMoney = walletMoneyBean.getUser_reward().getTixian_1();
            txtUserRewardMoney.setText("￥" + walletMoneyBean.getUser_reward().getTixian_1());
        }else {
            txtUserRewardMoney.setText("￥0");
            userMoney = "0";
        }
    }

}
